package com.health.db.dao.sm.impl;

import java.util.List;

import com.health.db.dao.ServiceInterface;
import com.health.db.dao.sm.IVersionControlDao;
import com.health.db.mapper.VersionControlMapper;
import com.health.db.model.VersionControl;
import com.health.db.model.VersionControlExt;
import com.health.redis.RedisConstants;
 

public class VersionControlDaoImpl  extends ServiceInterface implements IVersionControlDao {


 
	private VersionControlMapper versionControlMapper;

	String  selectBysetVersion=":version:";
	String  selectByPattern=":pattern:";
	String selectByFlag=":flag:";
	String state=":state:";

	/**
	 * example object
	 * {
	 *     flag     0客户版 1医生版
	 *     pattern  0 Android 1 IOS
	 *     version  版本号
	 *     state    1最新
	 * }
	 */
	@Override
	public List<VersionControl> selectByExample(VersionControlExt example) {
		
			List<VersionControl> list = null;
			getRedisOperatiorLogic();
			String key =RedisConstants.VersionControlMapper+selectBysetVersion+example.getVersion()
					+selectByPattern+example.getPattern()+selectByFlag+example.getFlag()+state+example.getState();
			
			Object object=null;
			
			if(redisOperatiorLogic.isJedisIsConnected())
			{	
				//get data from redis
				object = redisOperatiorLogic.readObject(key, getPublicRedisGroupNo("1"));
			 }
		
		     if(null!=object){
		    	 if (!object.equals("")) {
		    	 list =  (List<VersionControl>) object;
		    	 }
		     }else{
		 
			  list=versionControlMapper.selectByExample(example);
			  if(redisOperatiorLogic.isJedisIsConnected())
				{
					redisOperatiorLogic.setEx(key, list,  getOrderRedisGroupNo("1"));
				}
			 }
		return list;
	}

	
	public VersionControlMapper getVersionControlMapper() {
		return versionControlMapper;
	}

	public void setVersionControlMapper(VersionControlMapper versionControlMapper) {
		this.versionControlMapper = versionControlMapper;
	}

}
